#! /bin/sh


if [ $# -ne 2 ]; then
	echo "$0 prj-name prj-type"
	echo "Where:"
	echo "     prj-name is the name of the project"
	echo "     prj-type is 'app' or 'lib' "
	exit 10
fi

prj=$1
type=$2

if [ "$type" != "app" -a "$type" != "lib" ]; then
	echo "prj-type must be 'app' or 'lib'"
	exit 20
fi


if [ "$type" = "app" ]; then
	type_desc="program"
else
	type_desc="library"
fi

echo ""
echo "Creating directories for $type_desc '$prj'"
echo ""

mkdir "$prj" 2> /dev/null

mkdir -p "../../doc/$prj"  2> /dev/null

mkdir -p "../../etc/$prj"  2> /dev/null

mkdir -p "../../include/$prj"  2> /dev/null

mkdir -p "../../obj/$prj"  2> /dev/null

mkdir -p "../../src/$prj"  2> /dev/null

mkdir -p "../../var/$prj"  2> /dev/null

mkdir -p "../../test/$prj"  2> /dev/null


# creating the project file
prj_pro="$prj/$prj.pro"


echo ""                                 > "$prj_pro"
echo "QT       -= core gui"             >> "$prj_pro"
echo ""                                 >> "$prj_pro"
echo "TARGET = $prj"                    >> "$prj_pro"
echo ""                                 >> "$prj_pro"
echo "TEMPLATE = $type"                 >> "$prj_pro"
echo ""                                 >> "$prj_pro"
if [ "$type" = "lib" ]; then

	echo "CONFIG += staticlib"      >> "$prj_pro"
	echo "CONFIG += dll"            >> "$prj_pro"
	echo "DEFINES += $prj"_LIBRARY  >> "$prj_pro"
fi
echo ""                                 >> "$prj_pro"
echo "include (../tenacitas.pro)"       >> "$prj_pro"
echo ""                                 >> "$prj_pro"
echo "SOURCES = \$\$files(../../src/\$\$TARGET/*.cpp)" >>  "$prj_pro"
echo "HEADERS = \$\$files(../../include/\$\$TARGET/*.h)" >>  "$prj_pro"



# creating the test program

# well, it only makes sense, IMHO, to create test programs for libraries
if [ "$type" = "lib" ]; then
    test="test_$prj"
    test_pro="../../test/$prj/$test.pro"

    echo ""                                       > "$test_pro"
    echo "QT       -= core gui"                  >> "$test_pro"
    echo ""                                      >> "$test_pro"
    echo "TARGET = $test"                        >> "$test_pro"
    echo ""                                      >> "$test_pro"
    echo "PRJ = $prj"                            >> "$test_pro"
    echo ""                                      >> "$test_pro"
    echo "include (../tenacitas_test.pro)"       >> "$test_pro"
    echo ""                                      >> "$test_pro"
    echo "SOURCES = \$\$files(\$\$TARGET/*.cpp)" >> "$test_pro"
    echo ""                                      >> "$test_pro"
    echo "HEADERS = \$\$files(\$\$TARGET/*.h)"   >> "$test_pro"
fi





